package org.apache.lucene.ocean;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Commit result for a particular IndexSnapshot
 */
public class IndexSnapshotCommitResult {
  /**
   * IndexID of the of the Index this result was generated from
   */
  private IndexID indexId;
  private List<Result> results = new ArrayList<Result>();
  private int numDeleted = 0;
  private List<Long> docIds = new LinkedList<Long>(); 
  private int numAdded = 0;

  public IndexSnapshotCommitResult(IndexID indexId) {
    this.indexId = indexId;
  }

  public List<Long> getDocIds() {
    return docIds;
  }
  
  /**
   * Get the IndexID for this result
   * @return
   */
  public IndexID getIndexId() {
    return indexId;
  }
  
  void setNumAdded(int numAdded) {
    this.numAdded = numAdded;
  }
  
  /**
   * Add a Result
   * @param result
   */
  public void add(Result result) {
    numDeleted += result.getNumDeleted();
    results.add(result);
  }
  
  /**
   * Get the number of documents added to the snapshot
   * @return
   */
  public int getNumAdded() {
    return numAdded;
  }
  
  /**
   * Get the number of documents deleted from the snapshot
   * @return
   */
  public int getNumDeleted() {
    return numDeleted;
  }
  
  /**
   * For a particular delete (term or deletebyquery) contains the
   * number of documents deleted.
   *
   */
  public static class Result {
    private Object delete;
    private int numDeleted;

    public Result(Object delete, int numDeleted) {
      this.delete = delete;
      this.numDeleted = numDeleted;
    }

    public Object getDelete() {
      return delete;
    }

    public int getNumDeleted() {
      return numDeleted;
    }
  }
}